package com.appcheck.recording.listener.impl;

import android.view.View;
import android.view.View.OnFocusChangeListener;

import com.appcheck.recording.ListenerManager;
import com.appcheck.recording.action.impl.FocusAction;
import com.appcheck.recording.listener.AbstractListener;
import com.appcheck.recording.utils.Logger;

public class FocusChangeListener extends AbstractListener implements
		OnFocusChangeListener {
	private int b;
  
	public FocusChangeListener(View paramView){
		super(paramView, View.class, View.OnFocusChangeListener.class);
	}
	
	@Override
	public void onFocusChange(View v, boolean hasFocus) {
	    if (this.b++ > 1) {
	        return;
	    }
	    FocusAction focusAction = new FocusAction();
	    focusAction.setView(v);
	    focusAction.setState(hasFocus);
	    Logger.DEBUG("create FocusAction " + focusAction.toString());
	    ListenerManager.getListenerManager().handleAction(focusAction);
	    if (this.listener != null) {
	       ((View.OnFocusChangeListener)this.listener).onFocusChange(v, hasFocus);
	    }
	    this.b = 0;
	}

}
